package logic

import (
	"context"
	"fmt"
	"jd/models"

	"jd/userrpc/internal/svc"
	"jd/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserLoginLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLoginLogic {
	return &UserLoginLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserLoginLogic) UserLogin(in *userrpc.UserLoginRequest) (*userrpc.UserLoginResponse, error) {
	// todo: add your logic here and delete this line

	//验证码
	//code := in.CaptchaCode
	//get := models.Rdb.Get("captchalogin" + in.Mobile)
	//if get.Val() != code {
	//	return nil, fmt.Errorf("验证码输入有误请重新输入")
	//}
	//smsCode := in.SmsCode
	//cmd := models.Rdb.Get("sendSmslogin" + in.Mobile)
	//if cmd.Val() != smsCode {
	//	return nil, fmt.Errorf("短信验证码输入有误请重新输入")
	//}
	var user models.User
	models.Db.Debug().Where("mobile = ?", in.Mobile).Find(&user)
	if user.ID == 0 {
		return nil, fmt.Errorf("用户不存在")
	}
	return &userrpc.UserLoginResponse{}, nil
}
